// 方法1：写入to.txt
var fs = require("fs");
var path = require("path");

var filePath1 = path.join(__dirname, "/from.txt");
var readable = fs.createReadStream(filePath1);
var filePath2 = path.join(__dirname, "/to.txt");
var writeable = fs.createWriteStream(filePath2);

readable.on("data", function(chunk){
    var datas=chunk.toString("utf8").toUpperCase();
    console.log(datas);
    writeable.write(datas);
    writeable.end();
})
readable.on("end", function(){
    console.log("!")
})


// 方法2 ：用管道pipe机制 ，输出流到输入流
var fs = require("fs");
var path = require("path");

var filePath1 = path.join(__dirname, "/from.txt");
var readable = fs.createReadStream(filePath1);
var filePath2 = path.join(__dirname, "/to.txt");
var writerable = fs.createWriteStream(filePath2);

var stream = require("stream");
var Readable = stream.Readable;
var rs = new Readable();
rs._read = function(){

}
/**
 * 使用 rs.push方法 必须要引入 rs._read=function(){}
 * 就算里面是空函数也必须引入
 * 因为 rs.push 的时候会自动调用 rs._read=function(){}
 */
readable.on("data", function(chunk){
    rs.push(chunk.toString("utf8").toUpperCase());
    
})
readable.on("end", function(){
    console.log("!")
})

rs.pipe(writerable);


